/* File: StarTest.cc

**  This file is NOT part of the AQUA program suite but was developped
**  to start testing the compatibility of AQUA with the a c++ compiler.
 
   AUTHOR(S) : Dave Argentar, Steven Mading, and Eldon Ulrich
   DATE      : January 2001
   PURPOSE   : Testing only
*/


#include <fstream.h>
#include <stdio.h>
#include "ast.h"
#include "parser.h"
#include "scanner.h"


StarFileNode  *AST;   // StarFileNode is defined in "ast.h"
ofstream      *os;    // ofstream is in the standard libc++.

int main( void )
{

    yyin = fopen( "input.star", "r" );
    if( yyin == NULL )
    {   cerr << "Error opening input.star\n";
        return 2;
    }

    if( yyparse() == 0 )  // yyparse returns nonzero on error.
    {
        // It was successfully parsed, now *AST contains the
        // file in memory.  For this simple example, we will
        // just Unparse it right away and quit.
        // -------------------------------------------------
        os = new ofstream( "output.star" );
        if( os == NULL )
        {   cerr << "Error opening output.star\n";
            return 1;
        }
        AST->Unparse(0); // Unparse takes 1 arg: the indent level:
        delete os;   // C++ streams are closed by calling the delete
                     // operator.  If you do not close it, it might
                     // not flush the last line or two of the output.
        delete AST;
    }
    else
    {   cerr << "Syntax error while parsing file.\n";
        return 3;
    }

    return 0;
}
